package com.leizi.igym.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leizi.igym.domain.EquipCategory;
import com.leizi.igym.service.EquipCategoryService;
import com.leizi.igym.mapper.EquipCategoryMapper;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author PC
 * @description 针对表【t_equip_category(器械分类中间表)】的数据库操作Service实现
 * @createDate 2024-04-09 10:02:12
 */
@Service
public class EquipCategoryServiceImpl extends ServiceImpl<EquipCategoryMapper, EquipCategory>
        implements EquipCategoryService {

    /**
     * 根据传来的训练部位id查询满足条件的器械id集合，便于后面的含条件的分页查询
     *
     * @param part
     * @return: java.util.List<java.lang.Long>
     **/
    @Override
    public List<Long> getEquipIdByPart(Long part) {
        if (Objects.isNull(part) || part < 0) {
            return Collections.emptyList();
        }
        QueryWrapper<EquipCategory> qw = new QueryWrapper<>();
        qw.eq("category_id", part);
        List<EquipCategory> list = this.getBaseMapper().selectList(qw);
        if (CollectionUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list.stream().map(equipCategory -> equipCategory.getEquipId()).toList();
    }
}




